<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>zapmenot.shield &mdash; Zapmenot 0.1 documentation</title>
      <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../../index.html" class="icon icon-home"> Zapmenot
          </a>
              <div class="version">
                0.1
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">Licence &amp; Disclaimer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../materials.html">Material Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../isotopes.html">Isotope Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modeling.html">Modeling in ZapMeNot</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../results.html">Generating Results</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../graphics.html">We Want Pictures!</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../theory-and-methods.html">Theory and Methods</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../benchmarks.html">Benchmarking</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../module-docs.html">Module Contents</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../developer.html">Developer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../version-history.html">Version History</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Zapmenot</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
      <li class="breadcrumb-item active">zapmenot.shield</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for zapmenot.shield</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">abc</span>
<span class="kn">import</span> <span class="nn">math</span>
<span class="kn">import</span> <span class="nn">numbers</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">material</span><span class="p">,</span> <span class="n">ray</span>

<span class="kn">import</span> <span class="nn">importlib</span>
<span class="n">pyvista_spec</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">find_spec</span><span class="p">(</span><span class="s2">&quot;pyvista&quot;</span><span class="p">)</span>
<span class="n">pyvista_found</span> <span class="o">=</span> <span class="n">pyvista_spec</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">pyvista</span>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="Shield"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Shield">[docs]</a><span class="k">class</span> <span class="nc">Shield</span><span class="p">(</span><span class="n">abc</span><span class="o">.</span><span class="n">ABC</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Abtract class to model a photon shield.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`, optional</span>
<span class="sd">        Shield material type</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3</span>
<span class="sd">    **kwargs</span>
<span class="sd">        Arbitrary keyword arguments.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c1"># the material name is validated by the Material class</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">material</span> <span class="o">=</span> <span class="n">material</span><span class="o">.</span><span class="n">Material</span><span class="p">(</span><span class="n">material_name</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">density</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">density</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid density: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">density</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">density</span> <span class="o">=</span> <span class="n">density</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<div class="viewcode-block" id="Shield.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Shield.is_infinite">[docs]</a>    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span></div>

    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a_ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        a_ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a_ray</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">FiniteLengthRay</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid ray object&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="Shield.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Shield.get_crossing_mfp">[docs]</a>    <span class="nd">@abc</span><span class="o">.</span><span class="n">abstractmethod</span>
    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">a_ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        a_ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">a_ray</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">FiniteLengthRay</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid ray object&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">numbers</span><span class="o">.</span><span class="n">Number</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Invalid photon energy&quot;</span><span class="p">)</span></div>

    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">_line_plane_collision</span><span class="p">(</span><span class="n">plane_normal</span><span class="p">,</span> <span class="n">plane_point</span><span class="p">,</span> <span class="n">ray_origin</span><span class="p">,</span>
                              <span class="n">ray_normal</span><span class="p">,</span> <span class="n">epsilon</span><span class="o">=</span><span class="mf">1e-6</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the distance from the ray origin to the intersection</span>
<span class="sd">           with a plane</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        plane_normal : :class:`numpy.ndarray`</span>
<span class="sd">            A vector normal to the plane</span>
<span class="sd">        plane_point : :class:`numpy.ndarray`</span>
<span class="sd">            Vector location of an arbitrary point on the plane</span>
<span class="sd">        ray_origin : :class:`numpy.ndarray`</span>
<span class="sd">            The vector location of the ray origin</span>
<span class="sd">        ray_normal : :class:`numpy.ndarray`</span>
<span class="sd">            The vector normal of the ray</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>

<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        This work is based on</span>
<span class="sd">        &lt;https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ndotu</span> <span class="o">=</span> <span class="n">plane_normal</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">ray_normal</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">ndotu</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">epsilon</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="n">w</span> <span class="o">=</span> <span class="n">plane_point</span> <span class="o">-</span> <span class="n">ray_origin</span>
        <span class="n">t</span> <span class="o">=</span> <span class="n">w</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">plane_normal</span><span class="p">)</span><span class="o">/</span><span class="n">ndotu</span>
        <span class="k">return</span> <span class="n">t</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="SemiInfiniteXSlab"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.SemiInfiniteXSlab">[docs]</a><span class="k">class</span> <span class="nc">SemiInfiniteXSlab</span><span class="p">(</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A semi-infinite slab shield perpendicular to the X axis.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    x_start : float</span>
<span class="sd">        X axis location of the inner edge of the shield.</span>
<span class="sd">    x_end : float</span>
<span class="sd">        X axis location of the outer edge of the shield.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    x_start : float</span>
<span class="sd">        X axis location of the inner edge of the shield.</span>
<span class="sd">    x_end : float</span>
<span class="sd">        X axis location of the outer edge of the shield.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">x_start</span><span class="p">,</span> <span class="n">x_end</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_start</span> <span class="o">=</span> <span class="n">x_start</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">x_end</span> <span class="o">=</span> <span class="n">x_end</span>

<div class="viewcode-block" id="SemiInfiniteXSlab.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.SemiInfiniteXSlab.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">True</span></div>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>  <span class="c1"># validate the arguments</span>
        <span class="n">ray_origin</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span>
        <span class="n">ray_unit_vector</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span>
        <span class="n">plane_normal</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="c1"># get length to one crossing point</span>
        <span class="n">plane_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">x_start</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">first_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span>
            <span class="n">plane_normal</span><span class="p">,</span> <span class="n">plane_point</span><span class="p">,</span> <span class="n">ray_origin</span><span class="p">,</span> <span class="n">ray_unit_vector</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">first_length</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># ray is parallel to plane</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="c1"># get length to second crossing point</span>
        <span class="n">plane_point</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">x_end</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span>
        <span class="n">second_length</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span>
            <span class="n">plane_normal</span><span class="p">,</span> <span class="n">plane_point</span><span class="p">,</span> <span class="n">ray_origin</span><span class="p">,</span> <span class="n">ray_unit_vector</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">second_length</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="c1"># ray is parallel to plane</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">first_length</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">second_length</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">):</span>
            <span class="c1"># ray starts and ends entirely on one side of the shield</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">first_length</span> <span class="o">&gt;</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span> <span class="ow">and</span> <span class="n">second_length</span> <span class="o">&gt;</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">):</span>
            <span class="c1"># ray starts and ends entirely on one side of the shield</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="c1"># remainder of cases have some sort of partial or full crossing</span>
        <span class="n">t0</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">first_length</span><span class="p">,</span> <span class="n">second_length</span><span class="p">)</span>
        <span class="n">t1</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">first_length</span><span class="p">,</span> <span class="n">second_length</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">((</span><span class="n">t0</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">t1</span> <span class="o">&gt;</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">)):</span>
            <span class="c1"># ray is intirely within the slab</span>
            <span class="k">return</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span>
        <span class="k">if</span> <span class="p">((</span><span class="n">t0</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">t1</span> <span class="o">&lt;</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">)):</span>
            <span class="c1"># ray start in slab and crosses out</span>
            <span class="k">return</span> <span class="n">t1</span>
        <span class="k">if</span> <span class="p">((</span><span class="n">t0</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">t1</span> <span class="o">&gt;</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">)):</span>
            <span class="c1"># ray starts outside slab and ends inside slab</span>
            <span class="k">return</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span> <span class="o">-</span> <span class="n">t0</span>
        <span class="c1"># we are left with a full crossing</span>
        <span class="k">return</span> <span class="n">t1</span> <span class="o">-</span> <span class="n">t0</span>

<div class="viewcode-block" id="SemiInfiniteXSlab.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.SemiInfiniteXSlab.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># validate the arguments</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_crossing_mfp</span><span class="p">(</span><span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">)</span>
        <span class="n">distance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">get_mfp</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">distance</span><span class="p">)</span></div>

<div class="viewcode-block" id="SemiInfiniteXSlab.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.SemiInfiniteXSlab.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A box object representing the slab shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Box</span><span class="p">(</span><span class="n">bounds</span><span class="o">=</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_start</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">x_end</span><span class="p">,</span> <span class="o">-</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1000</span><span class="p">,</span>
                                       <span class="o">-</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">1000</span><span class="p">))</span></div>

    <span class="k">def</span> <span class="nf">_projection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">):</span>
        <span class="c1"># project a point onto the surface of the infinite shield</span>
        <span class="c1"># this is a semi-infinite slab, with a finite X width,</span>
        <span class="c1"># so return two x values at the specified y and z</span>
        <span class="k">return</span> <span class="p">[(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_start</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">),</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">x_end</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">)]</span></div>
<span class="c1"># -----------------------------------------------------------</span>


<span class="c1"># class Sphere(Shield):</span>
<span class="c1">#     def __init__(self, material_name, sphere_center, sphere_radius, density=None):</span>
<span class="c1">#         &#39;&#39;&#39;Initialize material composition and location of the slab shield&#39;&#39;&#39;</span>
<span class="c1">#         super().__init__(material_name=material_name, density=density)</span>
<span class="c1">#         self.center = np.array(sphere_center)</span>
<span class="c1">#         self.radius = np.array(sphere_radius)</span>

<span class="c1">#     def get_crossing_mfp(self, ray, photon_energy):</span>
<span class="c1">#         &#39;&#39;&#39;returns the crossing mfp&#39;&#39;&#39;</span>
<span class="c1">#         super().get_crossing_mfp(ray, photon_energy)    # validate the arguments</span>
<span class="c1">#         distance = self._get_crossing_length(ray)</span>
<span class="c1">#         return self.material.get_mfp(photon_energy, distance)</span>

<span class="c1">#     def _get_crossing_length(self, ray):</span>
<span class="c1">#         # based on</span>
<span class="c1">#         # http://viclw17.github.io/2018/07/16/raytracing-ray-sphere-intersection/</span>
<span class="c1">#         super()._get_crossing_length(ray)  # validate the arguments</span>
<span class="c1">#         a = np.dot(ray._dir, ray._dir)</span>
<span class="c1">#         b = 2 * np.dot(ray._dir, ray._origin - self.center)</span>
<span class="c1">#         c = np.dot(ray._origin-self.center, ray._origin -</span>
<span class="c1">#                    self.center) - self.radius**2</span>
<span class="c1">#         discriminant = b**2 - 4*a*c</span>
<span class="c1">#         if discriminant &lt;= 0:</span>
<span class="c1">#             # sphere is missed or tangent</span>
<span class="c1">#             return 0</span>
<span class="c1">#         root = np.sqrt(discriminant)</span>
<span class="c1">#         t0 = (-b - root)/(2*a)</span>
<span class="c1">#         t1 = (-b + root)/(2*a)</span>
<span class="c1">#         big_list = []</span>
<span class="c1">#         for a_length in [t0, t1]:</span>
<span class="c1">#             if (a_length &gt;= 0) and (a_length &lt;= ray._length):</span>
<span class="c1">#                 big_list.append(a_length)</span>
<span class="c1">#         if len(big_list) != 2:</span>
<span class="c1">#             # if not 2 intersections, look for ray endpoints inside the sphere</span>
<span class="c1">#             if self.contains(ray._origin):</span>
<span class="c1">#                 big_list.append(0)</span>
<span class="c1">#             if self.contains(ray._end):</span>
<span class="c1">#                 big_list.append(ray._length)</span>
<span class="c1">#         if len(big_list) == 0:</span>
<span class="c1">#             # ray misses the sphere</span>
<span class="c1">#             return 0</span>
<span class="c1">#         if len(big_list) != 2:</span>
<span class="c1">#             # this shouldn&#39;t occur</span>
<span class="c1">#             raise ValueError(&quot;Shield doesn&#39;t have 2 crossings&quot;)</span>
<span class="c1">#         return abs(big_list[1]-big_list[0])</span>

<span class="c1">#     def contains(self, point):</span>
<span class="c1">#         ray = point - self.center</span>
<span class="c1">#         if np.dot(ray, ray) &gt; self.radius**2:</span>
<span class="c1">#             return False</span>
<span class="c1">#         return True</span>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="Box"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Box">[docs]</a><span class="k">class</span> <span class="nc">Box</span><span class="p">(</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A rectangular polyhedron shield.</span>

<span class="sd">    All sides of the box shield must be axis-aligned.</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    box_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the box center.</span>
<span class="sd">    box_dimensions : :obj:`list`</span>
<span class="sd">        X, Y, and Z dimensions of the box.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class:material.Material</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    box_center : :class:numpy.ndarray</span>
<span class="sd">        Vector location of the center of the box in cartesian coordiantes.</span>
<span class="sd">    box_dimensions :  :class:numpy.ndarray</span>
<span class="sd">        Vector holding the dimensions of the box.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">box_center</span><span class="p">,</span> <span class="n">box_dimensions</span><span class="p">,</span>
                 <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">box_center</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">box_dimensions</span><span class="p">)</span>

<div class="viewcode-block" id="Box.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Box.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Box.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Box.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># validate the arguments</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_crossing_mfp</span><span class="p">(</span><span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">)</span>
        <span class="n">distance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">get_mfp</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">distance</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections with</span>
<span class="sd">            the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>  <span class="c1"># validate the arguments</span>
        <span class="n">crossings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_intersect_axis_aligned_box</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="c1"># two crossings indicates a full-shield crossing</span>
        <span class="c1"># one crossing indicates that either (common) the source is</span>
        <span class="c1">#    in the shield or (uncommon) the dose point is in the</span>
        <span class="c1">#    shield</span>
        <span class="c1"># zero crossings can indicate that either both source and</span>
        <span class="c1">#    dose points are in the shield or that the shield is</span>
        <span class="c1">#    missed entirely</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c1"># check for start/end of ray within the box</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_end</span><span class="p">)):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_end</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># likely it&#39;s a complete miss</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c1"># shouldn&#39;t ever get here</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Shield doesn&#39;t have 2 crossings&quot;</span><span class="p">)</span>
        <span class="c1"># let numpy do the heavy lifting</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">crossings</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">crossings</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">_contains</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Determines if the shield contains a point</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        point : :obj:`list`</span>
<span class="sd">            The X, Y, and Z cartesian coordinates of a point.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        boolean</span>
<span class="sd">            True if the box contains the point, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">point</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">point</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">point</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">xmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">xmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">ymin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">ymax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">zmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="n">zmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">xmin</span> <span class="o">&lt;=</span> <span class="n">x</span> <span class="ow">and</span> <span class="n">x</span> <span class="o">&lt;=</span> <span class="n">xmax</span> <span class="ow">and</span> <span class="n">ymin</span> <span class="o">&lt;=</span> <span class="n">y</span> <span class="ow">and</span> <span class="n">y</span> <span class="o">&lt;=</span> <span class="n">ymax</span> <span class="ow">and</span> <span class="n">zmin</span> <span class="o">&lt;=</span> <span class="n">z</span>
                <span class="ow">and</span> <span class="n">z</span> <span class="o">&lt;=</span> <span class="n">zmax</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="nf">_intersect_axis_aligned_box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates a list of point where a ray intersects the</span>
<span class="sd">           axis-aligned box</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :obj:`ray.Ray`</span>
<span class="sd">            A ray object that may intersect the box.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :obj:`list`</span>
<span class="sd">            List of vector locations of intersection points.  These will</span>
<span class="sd">            include the ray endpoints if they are located within the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="s1">&#39;returns 0, 1, or 2 points of intersection&#39;</span>
        <span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">bounds</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">box_center</span> <span class="o">-</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="o">/</span><span class="mi">2</span><span class="p">),</span>
                  <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="o">/</span><span class="mi">2</span><span class="p">)]</span>
        <span class="n">tmin</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">tmax</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="o">-</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">tymin</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">tymax</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="o">-</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">tmin</span> <span class="o">&gt;</span> <span class="n">tymax</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">tymin</span> <span class="o">&gt;</span> <span class="n">tmax</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">results</span>

        <span class="k">if</span> <span class="n">tymin</span> <span class="o">&gt;</span> <span class="n">tmin</span><span class="p">:</span>
            <span class="n">tmin</span> <span class="o">=</span> <span class="n">tymin</span>
        <span class="k">if</span> <span class="n">tymax</span> <span class="o">&lt;</span> <span class="n">tmax</span><span class="p">:</span>
            <span class="n">tmax</span> <span class="o">=</span> <span class="n">tymax</span>

        <span class="n">tzmin</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">2</span><span class="p">]][</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">tzmax</span> <span class="o">=</span> <span class="p">(</span><span class="n">bounds</span><span class="p">[</span><span class="mi">1</span><span class="o">-</span><span class="n">ray</span><span class="o">.</span><span class="n">_sign</span><span class="p">[</span><span class="mi">2</span><span class="p">]][</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">*</span> <span class="n">ray</span><span class="o">.</span><span class="n">_invdir</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>

        <span class="k">if</span> <span class="p">((</span><span class="n">tmin</span> <span class="o">&gt;</span> <span class="n">tzmax</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">tzmin</span> <span class="o">&gt;</span> <span class="n">tmax</span><span class="p">)):</span>
            <span class="k">return</span> <span class="n">results</span>

        <span class="k">if</span> <span class="n">tzmin</span> <span class="o">&gt;</span> <span class="n">tmin</span><span class="p">:</span>
            <span class="n">tmin</span> <span class="o">=</span> <span class="n">tzmin</span>

        <span class="k">if</span> <span class="n">tzmax</span> <span class="o">&lt;</span> <span class="n">tmax</span><span class="p">:</span>
            <span class="n">tmax</span> <span class="o">=</span> <span class="n">tzmax</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">tmin</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">tmin</span> <span class="o">&lt;=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">):</span>
            <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">+</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="o">*</span><span class="n">tmin</span><span class="p">)</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">tmax</span> <span class="o">&gt;=</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">tmax</span> <span class="o">&lt;=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">):</span>
            <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">+</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="o">*</span><span class="n">tmax</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">results</span>

<div class="viewcode-block" id="Box.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.Box.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A box object representing the box shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="n">xmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">xmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">ymin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">ymax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">zmin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="n">zmax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">box_dimensions</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">/</span><span class="mi">2</span>
            <span class="k">return</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Box</span><span class="p">(</span><span class="n">bounds</span><span class="o">=</span><span class="p">(</span><span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">))</span></div></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="InfiniteAnnulus"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.InfiniteAnnulus">[docs]</a><span class="k">class</span> <span class="nc">InfiniteAnnulus</span><span class="p">(</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;An annular shield of infinite length</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_origin : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the point on the cylinder centerline.</span>
<span class="sd">    cylinder_axis : :obj:`list`</span>
<span class="sd">        X, Y, and Z vector components of the cylinder axis.</span>
<span class="sd">    cylinder_inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    cylinder_outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of a point on the annulus centerline.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the annulus centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_origin</span><span class="p">,</span> <span class="n">cylinder_axis</span><span class="p">,</span>
                 <span class="n">cylinder_inner_radius</span><span class="p">,</span> <span class="n">cylinder_outer_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">inner_radius</span> <span class="o">=</span> <span class="n">cylinder_inner_radius</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">outer_radius</span> <span class="o">=</span> <span class="n">cylinder_outer_radius</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cylinder_origin</span><span class="p">)</span>
        <span class="n">axis</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cylinder_axis</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dir</span> <span class="o">=</span> <span class="n">axis</span><span class="o">/</span><span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">axis</span><span class="p">)</span>

<div class="viewcode-block" id="InfiniteAnnulus.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.InfiniteAnnulus.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="InfiniteAnnulus.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.InfiniteAnnulus.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># validate the arguments</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_crossing_mfp</span><span class="p">(</span><span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">)</span>
        <span class="n">distance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">get_mfp</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">distance</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>  <span class="c1"># validate the arguments</span>
        <span class="c1"># get a list of crossing points</span>
        <span class="n">crossings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_intersect</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="c1"># zero crossings can indicate that either both source and</span>
        <span class="c1">#    dose points are in the shield or that the shield is</span>
        <span class="c1">#    missed entirely</span>
        <span class="c1"># one crossing indicates that either (common) the source is</span>
        <span class="c1">#    in the shield or (uncommon) the dose point is in the</span>
        <span class="c1">#    shield</span>
        <span class="c1"># two crossings indicates a single in/out or out/in crossing</span>
        <span class="c1"># four crossings indicate a full-shield crossing</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">]:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_end</span><span class="p">)):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">4</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Shield doesn&#39;t have valid crossings&quot;</span><span class="p">)</span>
        <span class="n">crossings</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">crossings</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">crossings</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="c1"># let numpy do the heavy lifting</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">crossings</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">crossings</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="p">(</span><span class="n">crossings</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">crossings</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">_contains</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Determines if the shield contains a point</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        point : :obj:`list`</span>
<span class="sd">            The X, Y, and Z cartesian coordinates of a point.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        boolean</span>
<span class="sd">            True if the shield contains the point, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># determine scalar projection of point on cylinder centerline</span>
        <span class="n">rando</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">point</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="c1"># check the radial distance from cylinder centerline</span>
        <span class="n">parto</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="n">rando</span><span class="p">)</span> <span class="o">-</span> <span class="n">point</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">parto</span><span class="p">,</span> <span class="n">parto</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">inner_radius</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> <span class="ow">or</span> \
                <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">parto</span><span class="p">,</span> <span class="n">parto</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">outer_radius</span><span class="o">**</span><span class="mi">2</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span>

    <span class="k">def</span> <span class="nf">_intersect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates a list of points where a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :obj:`ray.Ray`</span>
<span class="sd">            A ray object that may intersect the box.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :obj:`list`</span>
<span class="sd">            List of distances along the ray, measured from the ray origin,</span>
<span class="sd">            where the ray intersects the annulus.  Will include the ray</span>
<span class="sd">            endpoints if they are within the annular shield.</span>
<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        This work is based on</span>
<span class="sd">        &lt;https://mrl.nyu.edu/~dzorin/rend05/lecture2.pdf&gt;</span>
<span class="sd">        and</span>
<span class="sd">        &lt;https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">radius</span> <span class="ow">in</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">inner_radius</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">outer_radius</span><span class="p">]:</span>
            <span class="n">deltap</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span>
            <span class="n">part1</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span> <span class="o">-</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
            <span class="n">part2</span> <span class="o">=</span> <span class="n">deltap</span> <span class="o">-</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">deltap</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
            <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part1</span><span class="p">,</span> <span class="n">part1</span><span class="p">)</span>
            <span class="n">b</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part1</span><span class="p">,</span> <span class="n">part2</span><span class="p">)</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part2</span><span class="p">,</span> <span class="n">part2</span><span class="p">)</span> <span class="o">-</span> <span class="n">radius</span><span class="o">**</span><span class="mi">2</span>
            <span class="n">zoro</span> <span class="o">=</span> <span class="n">b</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">4</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">c</span>
            <span class="k">if</span> <span class="n">zoro</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="c1"># roots are real, then are two intersections on an</span>
                <span class="c1"># &quot;infinite&quot; cylinder</span>
                <span class="n">meo</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">zoro</span><span class="p">)</span>
                <span class="n">t1</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">b</span> <span class="o">+</span> <span class="n">meo</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">a</span><span class="p">)</span>
                <span class="n">t2</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">b</span> <span class="o">-</span> <span class="n">meo</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">a</span><span class="p">)</span>
                <span class="c1"># check to see if the intersections occur in the finite</span>
                <span class="c1"># length of the cylinder</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="p">[</span><span class="n">t1</span><span class="p">,</span> <span class="n">t2</span><span class="p">]:</span>
                    <span class="c1"># discard line/cylinder intersections outside of the</span>
                    <span class="c1"># length of the ray</span>
                    <span class="k">if</span> <span class="n">t</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">t</span> <span class="o">&lt;=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">:</span>
                        <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">results</span>

<div class="viewcode-block" id="InfiniteAnnulus.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.InfiniteAnnulus.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A boolean object representing the annular cylinder shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="c1"># define an imaginary bottom of the shield at a distance</span>
            <span class="c1"># of -2000 from the origin</span>
            <span class="n">bottom</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="p">(</span><span class="o">-</span><span class="mf">2000.</span><span class="p">)</span>
            <span class="n">disc</span> <span class="o">=</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Disc</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="n">bottom</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">bottom</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">bottom</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                <span class="n">normal</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">,</span>
                                <span class="n">inner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">inner_radius</span><span class="p">,</span>
                                <span class="n">outer</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">outer_radius</span><span class="p">,</span> <span class="n">c_res</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
            <span class="n">cyl1</span> <span class="o">=</span> <span class="n">disc</span><span class="o">.</span><span class="n">extrude</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="mi">4000</span><span class="p">,</span> <span class="n">capping</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">cyl1</span></div>

    <span class="k">def</span> <span class="nf">_projection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">):</span>
        <span class="c1"># TODO: generalize this by using a degenerate cylinder</span>
        <span class="c1">#</span>
        <span class="c1"># project a point onto the surface of the infinite shield</span>
        <span class="c1"># this is a unconstrained annulus.</span>
        <span class="c1"># Given the range of possible geometries, this</span>
        <span class="c1"># routine will return a single x,y,z tuple representing</span>
        <span class="c1"># the interesection of the annulus axis with the plane of</span>
        <span class="c1"># the point.  Three possible intersections with the x, y,</span>
        <span class="c1"># and z planes of the point.  The closest point will</span>
        <span class="c1"># be returned.  This should permit the annulus to be displayed</span>
        <span class="c1"># without overly extending the region displayed.</span>
        <span class="n">normal</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="n">plane_point</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="p">]</span>
        <span class="n">intersection_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">normal</span><span class="p">),</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">plane_point</span><span class="p">),</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">t</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">intersection_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
        <span class="n">normal</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">normal</span><span class="p">),</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">plane_point</span><span class="p">),</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">t</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">intersection_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
        <span class="n">normal</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span>
        <span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">normal</span><span class="p">),</span>
                                       <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">plane_point</span><span class="p">),</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span>
                                       <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">t</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">intersection_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
        <span class="n">min_collision_distance</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">intersection</span> <span class="ow">in</span> <span class="n">intersection_list</span><span class="p">:</span>
            <span class="n">distance</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">intersection</span> <span class="o">-</span> <span class="n">plane_point</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">min_collision_distance</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> \
               <span class="p">(</span><span class="n">distance</span> <span class="o">&lt;</span> <span class="n">min_collision_distance</span><span class="p">):</span>
                    <span class="n">min_collision_distance</span> <span class="o">=</span> <span class="n">distance</span>
                    <span class="n">collision_point</span> <span class="o">=</span> <span class="n">intersection</span>
        <span class="n">fakeElipsisRadius</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">outer_radius</span>
        <span class="c1"># generate a bounding box centered at &quot;center&quot; and</span>
        <span class="c1"># a width of 2*outer_radius</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">collision_point</span> <span class="o">-</span> <span class="p">[</span><span class="n">fakeElipsisRadius</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                <span class="n">collision_point</span> <span class="o">+</span> <span class="p">[</span><span class="n">fakeElipsisRadius</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                <span class="n">collision_point</span> <span class="o">-</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">fakeElipsisRadius</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                <span class="n">collision_point</span> <span class="o">+</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="n">fakeElipsisRadius</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                <span class="n">collision_point</span> <span class="o">-</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">fakeElipsisRadius</span><span class="p">],</span>
                <span class="n">collision_point</span> <span class="o">+</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">fakeElipsisRadius</span><span class="p">]]</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="YAlignedInfiniteAnnulus"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.YAlignedInfiniteAnnulus">[docs]</a><span class="k">class</span> <span class="nc">YAlignedInfiniteAnnulus</span><span class="p">(</span><span class="n">InfiniteAnnulus</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;An annular shield of infinite length aligned with the Y axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the point on the cylinder centerline.</span>
<span class="sd">    cylinder_inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    cylinder_outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of a point on the annulus centerline.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the annulus centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_inner_radius</span><span class="p">,</span>
                 <span class="n">cylinder_outer_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_origin</span><span class="o">=</span><span class="n">cylinder_center</span><span class="p">,</span>
                         <span class="n">cylinder_inner_radius</span><span class="o">=</span><span class="n">cylinder_inner_radius</span><span class="p">,</span>
                         <span class="n">cylinder_outer_radius</span><span class="o">=</span><span class="n">cylinder_outer_radius</span><span class="p">,</span>
                         <span class="n">cylinder_axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="XAlignedInfiniteAnnulus"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.XAlignedInfiniteAnnulus">[docs]</a><span class="k">class</span> <span class="nc">XAlignedInfiniteAnnulus</span><span class="p">(</span><span class="n">InfiniteAnnulus</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;An annular shield of infinite length aligned with the X axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the point on the cylinder centerline.</span>
<span class="sd">    cylinder_inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    cylinder_outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of a point on the annulus centerline.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the annulus centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_inner_radius</span><span class="p">,</span>
                 <span class="n">cylinder_outer_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_origin</span><span class="o">=</span><span class="n">cylinder_center</span><span class="p">,</span>
                         <span class="n">cylinder_inner_radius</span><span class="o">=</span><span class="n">cylinder_inner_radius</span><span class="p">,</span>
                         <span class="n">cylinder_outer_radius</span><span class="o">=</span><span class="n">cylinder_outer_radius</span><span class="p">,</span>
                         <span class="n">cylinder_axis</span><span class="o">=</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">])</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="ZAlignedInfiniteAnnulus"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.ZAlignedInfiniteAnnulus">[docs]</a><span class="k">class</span> <span class="nc">ZAlignedInfiniteAnnulus</span><span class="p">(</span><span class="n">InfiniteAnnulus</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;An annular shield of infinite length aligned with the Z axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the point on the cylinder centerline.</span>
<span class="sd">    cylinder_inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    cylinder_outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    inner_radius : float</span>
<span class="sd">        Radius of the annulus inner surface.</span>
<span class="sd">    outer_radius : float</span>
<span class="sd">        Radius of the annulus outer surface.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location of a point on the annulus centerline.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the annulus centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_inner_radius</span><span class="p">,</span>
                 <span class="n">cylinder_outer_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_origin</span><span class="o">=</span><span class="n">cylinder_center</span><span class="p">,</span>
                         <span class="n">cylinder_inner_radius</span><span class="o">=</span><span class="n">cylinder_inner_radius</span><span class="p">,</span>
                         <span class="n">cylinder_outer_radius</span><span class="o">=</span><span class="n">cylinder_outer_radius</span><span class="p">,</span>
                         <span class="n">cylinder_axis</span><span class="o">=</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="CappedCylinder"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.CappedCylinder">[docs]</a><span class="k">class</span> <span class="nc">CappedCylinder</span><span class="p">(</span><span class="n">Shield</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A cylindrical shield of finite length</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_start : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of one cylinder end.</span>
<span class="sd">    cylinder_end : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of another cylinder end.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_start`.</span>
<span class="sd">    end : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_end`.</span>
<span class="sd">    length : float</span>
<span class="sd">        Length of the cylinder.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the cylinder centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_start</span><span class="p">,</span> <span class="n">cylinder_end</span><span class="p">,</span>
                 <span class="n">cylinder_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">radius</span> <span class="o">=</span> <span class="n">cylinder_radius</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cylinder_start</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">cylinder_end</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">length</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dir</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">end</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">)</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span>

<div class="viewcode-block" id="CappedCylinder.is_infinite"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.CappedCylinder.is_infinite">[docs]</a>    <span class="k">def</span> <span class="nf">is_infinite</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Returns true if any dimension is infinite, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="CappedCylinder.get_crossing_mfp"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.CappedCylinder.get_crossing_mfp">[docs]</a>    <span class="k">def</span> <span class="nf">get_crossing_mfp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the mfp equivalent if a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        photon_energy : float</span>
<span class="sd">            The photon energy in MeV</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># validate the arguments</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_crossing_mfp</span><span class="p">(</span><span class="n">ray</span><span class="p">,</span> <span class="n">photon_energy</span><span class="p">)</span>
        <span class="n">distance</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">material</span><span class="o">.</span><span class="n">get_mfp</span><span class="p">(</span><span class="n">photon_energy</span><span class="p">,</span> <span class="n">distance</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="nf">_get_crossing_length</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates the linear intersection length of a ray and the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :class:`ray.FiniteLengthRay`</span>
<span class="sd">            The finite length ray that is checked for intersections</span>
<span class="sd">            with the shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_get_crossing_length</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>  <span class="c1"># validate the arguments</span>
        <span class="c1"># get a list of crossing points</span>
        <span class="n">crossings</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_intersect</span><span class="p">(</span><span class="n">ray</span><span class="p">)</span>
        <span class="c1"># two crossings indicates a full-shield crossing</span>
        <span class="c1"># one crossing indicates that either (common) the source is</span>
        <span class="c1">#    in the shield or (uncommon) the dose point is in the</span>
        <span class="c1">#    shield</span>
        <span class="c1"># zero crossings can indicate that either both source and</span>
        <span class="c1">#    dose points are in the shield or that the shield is</span>
        <span class="c1">#    missed entirely</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c1"># check for start/end of ray within the cylinder</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contains</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_end</span><span class="p">)):</span>
                <span class="n">crossings</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_end</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># likely it&#39;s a complete miss</span>
            <span class="k">return</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">crossings</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c1"># shouldn&#39;t ever get here</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Shield doesn&#39;t have 2 crossings&quot;</span><span class="p">)</span>
        <span class="c1"># let numpy do the heavy lifting</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">norm</span><span class="p">(</span><span class="n">crossings</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">crossings</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

    <span class="k">def</span> <span class="nf">_contains</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">point</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Determines if the shield contains a point</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        point : :obj:`list`</span>
<span class="sd">            The X, Y, and Z cartesian coordinates of a point.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        boolean</span>
<span class="sd">            True if the shield contains the point, false otherwise</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># determine scalar projection of point on cylinder centerline</span>
        <span class="n">rando</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">point</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rando</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">rando</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="c1"># check the radial distance from cylinder centerline</span>
        <span class="n">parto</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="o">*</span><span class="n">rando</span><span class="p">)</span> <span class="o">-</span> <span class="n">point</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">parto</span><span class="p">,</span> <span class="n">parto</span><span class="p">)</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="o">**</span><span class="mi">2</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span>

    <span class="k">def</span> <span class="nf">_intersect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ray</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Calculates a list of points where a ray intersects the shield</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        ray : :obj:`ray.Ray`</span>
<span class="sd">            A ray object that may intersect the box.</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :obj:`list`</span>
<span class="sd">            List of points along the ray</span>
<span class="sd">            where the ray intersects the annulus.  Will include the ray</span>
<span class="sd">            endpoints if they are within the annular shield.</span>
<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        This work is based on</span>
<span class="sd">        &lt;https://mrl.nyu.edu/~dzorin/rend05/lecture2.pdf&gt;</span>
<span class="sd">        and</span>
<span class="sd">        &lt;https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c1"># test for</span>
        <span class="n">deltap</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">origin</span>
        <span class="n">part1</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span> <span class="o">-</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="n">part2</span> <span class="o">=</span> <span class="n">deltap</span> <span class="o">-</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">deltap</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
        <span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part1</span><span class="p">,</span> <span class="n">part1</span><span class="p">)</span>
        <span class="n">b</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part1</span><span class="p">,</span> <span class="n">part2</span><span class="p">)</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">part2</span><span class="p">,</span> <span class="n">part2</span><span class="p">)</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="o">**</span><span class="mi">2</span>
        <span class="n">zoro</span> <span class="o">=</span> <span class="n">b</span><span class="o">**</span><span class="mi">2</span> <span class="o">-</span> <span class="mi">4</span><span class="o">*</span><span class="n">a</span><span class="o">*</span><span class="n">c</span>
        <span class="k">if</span> <span class="n">zoro</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="c1"># roots are real, then are two intersections on an</span>
            <span class="c1"># &quot;infinite&quot; cylinder</span>
            <span class="n">meo</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">zoro</span><span class="p">)</span>
            <span class="n">t1</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">b</span> <span class="o">+</span> <span class="n">meo</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">a</span><span class="p">)</span>
            <span class="n">t2</span> <span class="o">=</span> <span class="p">(</span><span class="o">-</span><span class="n">b</span> <span class="o">-</span> <span class="n">meo</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">a</span><span class="p">)</span>
            <span class="c1"># check to see if the intersections occur in the finite length</span>
            <span class="c1"># of the cylinder</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="p">[</span><span class="n">t1</span><span class="p">,</span> <span class="n">t2</span><span class="p">]:</span>
                <span class="c1"># discard line/cylinder intersections outside of the</span>
                <span class="c1"># length of the ray</span>
                <span class="k">if</span> <span class="n">t</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">t</span> <span class="o">&lt;=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">:</span>
                    <span class="n">intersection</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">+</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="o">*</span><span class="n">t</span>
                    <span class="n">loc</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">intersection</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">)</span>
                    <span class="c1"># keep only intersections within the finite length</span>
                    <span class="c1"># of the cylinder</span>
                    <span class="k">if</span> <span class="n">loc</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">loc</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">:</span>
                        <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">intersection</span><span class="p">)</span>
        <span class="c1"># check to see if there are intersections on the caps</span>
        <span class="k">for</span> <span class="n">disk_center</span> <span class="ow">in</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">]:</span>
            <span class="n">t</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_plane_collision</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">,</span> <span class="n">disk_center</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span><span class="p">,</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">t</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">t</span> <span class="o">&gt;=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">t</span> <span class="o">&lt;=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_length</span><span class="p">:</span>
                <span class="n">point</span> <span class="o">=</span> <span class="n">ray</span><span class="o">.</span><span class="n">_origin</span> <span class="o">+</span> <span class="n">ray</span><span class="o">.</span><span class="n">_dir</span><span class="o">*</span><span class="n">t</span>
                <span class="n">radial</span> <span class="o">=</span> <span class="n">point</span> <span class="o">-</span> <span class="n">disk_center</span>
                <span class="k">if</span> <span class="n">radial</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">radial</span><span class="p">)</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="o">**</span><span class="mi">2</span><span class="p">:</span>
                    <span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">point</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">results</span>

<div class="viewcode-block" id="CappedCylinder.draw"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.CappedCylinder.draw">[docs]</a>    <span class="k">def</span> <span class="nf">draw</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a display object</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        :class:`pyvista.PolyData`</span>
<span class="sd">            A cylinder object representing the capped cylinder shield.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">pyvista_found</span><span class="p">:</span>
            <span class="n">center</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">origin</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">end</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>
            <span class="k">return</span> <span class="n">pyvista</span><span class="o">.</span><span class="n">Cylinder</span><span class="p">(</span><span class="n">center</span><span class="o">=</span><span class="p">(</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
                                    <span class="n">direction</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">dir</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">,</span>
                                    <span class="n">radius</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">radius</span><span class="p">)</span></div></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="YAlignedCylinder"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.YAlignedCylinder">[docs]</a><span class="k">class</span> <span class="nc">YAlignedCylinder</span><span class="p">(</span><span class="n">CappedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A cylindrical shield of finite length aligned with the Y axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_start`.</span>
<span class="sd">    end : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_end`.</span>
<span class="sd">    length : float</span>
<span class="sd">        Length of the cylinder.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the cylinder centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_length</span><span class="p">,</span>
                 <span class="n">cylinder_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">cylinder_start</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="n">cylinder_length</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
        <span class="n">cylinder_end</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span>
                        <span class="n">cylinder_length</span><span class="o">/</span><span class="mi">2</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_start</span><span class="o">=</span><span class="n">cylinder_start</span><span class="p">,</span>
                         <span class="n">cylinder_end</span><span class="o">=</span><span class="n">cylinder_end</span><span class="p">,</span>
                         <span class="n">cylinder_radius</span><span class="o">=</span><span class="n">cylinder_radius</span><span class="p">)</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="XAlignedCylinder"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.XAlignedCylinder">[docs]</a><span class="k">class</span> <span class="nc">XAlignedCylinder</span><span class="p">(</span><span class="n">CappedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A cylindrical shield of finite length aligned with the X axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_start`.</span>
<span class="sd">    end : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_end`.</span>
<span class="sd">    length : float</span>
<span class="sd">        Length of the cylinder.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the cylinder centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_length</span><span class="p">,</span>
                 <span class="n">cylinder_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">cylinder_start</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">cylinder_length</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
        <span class="n">cylinder_end</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="n">cylinder_length</span> <span class="o">/</span> <span class="mi">2</span><span class="p">,</span>
                        <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                        <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_start</span><span class="o">=</span><span class="n">cylinder_start</span><span class="p">,</span>
                         <span class="n">cylinder_end</span><span class="o">=</span><span class="n">cylinder_end</span><span class="p">,</span>
                         <span class="n">cylinder_radius</span><span class="o">=</span><span class="n">cylinder_radius</span><span class="p">)</span></div>

<span class="c1"># -----------------------------------------------------------</span>


<div class="viewcode-block" id="ZAlignedCylinder"><a class="viewcode-back" href="../../module-docs.html#zapmenot.shield.ZAlignedCylinder">[docs]</a><span class="k">class</span> <span class="nc">ZAlignedCylinder</span><span class="p">(</span><span class="n">CappedCylinder</span><span class="p">):</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;A cylindrical shield of finite length aligned with the Z axis</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    material_name : :obj:`material.Material`</span>
<span class="sd">        Shield material type</span>
<span class="sd">    cylinder_center : :obj:`list`</span>
<span class="sd">        X, Y, and Z coordinates of the center of the cylinder.</span>
<span class="sd">    cylinder_length : float</span>
<span class="sd">        The length of the cylinder.</span>
<span class="sd">    cylinder_radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    density : float, optional</span>
<span class="sd">        Material density in g/cm3.</span>
<span class="sd">    &quot;&quot;&quot;</span>
<span class="w">    </span><span class="sd">&#39;&#39;&#39;</span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    material : :class: `material.Material`</span>
<span class="sd">        Material properties of the shield</span>
<span class="sd">    radius : float</span>
<span class="sd">        Radius of the cylinder.</span>
<span class="sd">    origin : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_start`.</span>
<span class="sd">    end : :class:`numpy.ndarray`</span>
<span class="sd">        Vector location corresponding to `cylinder_end`.</span>
<span class="sd">    length : float</span>
<span class="sd">        Length of the cylinder.</span>
<span class="sd">    dir : :class:`numpy.ndarray`</span>
<span class="sd">        Vector normal of the cylinder centerline.</span>
<span class="sd">    &#39;&#39;&#39;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_name</span><span class="p">,</span> <span class="n">cylinder_center</span><span class="p">,</span> <span class="n">cylinder_length</span><span class="p">,</span>
                 <span class="n">cylinder_radius</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="n">cylinder_start</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                          <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="n">cylinder_length</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">cylinder_end</span> <span class="o">=</span> <span class="p">[</span><span class="n">cylinder_center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                        <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                        <span class="n">cylinder_center</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">+</span><span class="n">cylinder_length</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">material_name</span><span class="o">=</span><span class="n">material_name</span><span class="p">,</span> <span class="n">density</span><span class="o">=</span><span class="n">density</span><span class="p">,</span>
                         <span class="n">cylinder_start</span><span class="o">=</span><span class="n">cylinder_start</span><span class="p">,</span>
                         <span class="n">cylinder_end</span><span class="o">=</span><span class="n">cylinder_end</span><span class="p">,</span>
                         <span class="n">cylinder_radius</span><span class="o">=</span><span class="n">cylinder_radius</span><span class="p">)</span></div>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2019 - 2023, Alan Ford..
      <span class="lastupdated">Last updated on Feb 12, 2023.
      </span></p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>